package com.datastructure.test.sortedarraytobalancebinarytree;

public class SortedArrayToBalanceBinaryTree {

    public static void main(String[] args) {

    }

    public TreeNode sortedArrayToBST (int[] num) {
        // write code here
        return dp(num,0,num.length-1);

    }
    public TreeNode dp(int num[],int left,int right){
        if(left > right){
            return null;
        }
        int val=(left+right)/2;
        TreeNode root=new TreeNode(num[val]);
        root.left=dp(num,left,val-1);
        root.right=dp(num,val+1,right);
        return root;
    }
}

class TreeNode {
    int val = 0;

    public TreeNode(int val) {
        this.val = val;
    }

    TreeNode left = null;
    TreeNode right = null;
}
